<?php
class Application_Model_Galleries extends Zend_Db_Table_Abstract
{
    protected $_name = 'galleries';

    public function getGallery($id)
    {
        $id = (int)$id;
        $row = $this->fetchRow('id = ' . $id);
        if (!$row) {
            throw new Exception("Count not find row $id");
        }
        return $row->toArray();
    }

    public function addGallery($title, $msg, $namefile, $datet)
    {
        $data = array(
            'title' => $title,
            'msg' => $msg,
            'namefile' => $namefile,
            'datet' => $datet,
        );
        $this->insert($data);
    }

    public function updateGallery($id, $title, $msg, $namefile)
    {
        $data = array(
            'title' => $title,
            'msg' => $msg,
            'namefile' => $namefile,
        );
        $this->update($data, 'id = '. (int)$id);
    }

    public function update2Gallery($id, $title, $msg)
    {
        $data = array(
            'title' => $title,
            'msg' => $msg,
        );
        $this->update($data, 'id = '. (int)$id);
    }

    public function deleteGallery($id)
    {
        $this->delete('id =' . (int)$id);
    }
}
